

function checkExecutableSkill_WildFlower(obj)  
{
	if (!obj) return false;

	local isUseSkill = obj.sq_IsUseSkill(SKILL_WILD_FLOWER);
	if (isUseSkill) 
	{

		obj.getVar("GLOBAL_PARAMETER_CANCEL").set_vector(0,0);
		local pIntVec = sq_GetGlobalIntVector();
		sq_IntVectorClear(pIntVec);
		sq_IntVectorPush(pIntVec, 0);			
		obj.addSetStatePacket(STATE_WILD_FLOWER , pIntVec,  STATE_PRIORITY_USER, false, "");

		return true;
	}
	return false;
}

function checkCommandEnable_WildFlower(obj)
{


	return true;
}

function onSetState_WildFlower(obj, state, datas, isResetTimer)
{
	obj.sq_StopMove();
	local state = obj.sq_GetVectorData(datas, 0);
	obj.setSkillSubState(state);
	if (state == 0)
	{
		obj.sq_SetCurrentAnimation( CUSTOM_ANI_WILD_FLOWER_CASTING );

		obj.getVar("flag").clear_vector();
		obj.getVar("flag").push_vector(0);
		obj.getVar("flag").push_vector(0);
		obj.getVar("flag").push_vector(0);
		obj.getVar("flag").push_vector(0);	
		local pAni = obj.sq_GetCurrentAni();
		pAni.setSpeedRate(150.0 );

	}else if (state == 1)
	{
		createWildFlowerStartDustBack(obj);
		obj.sq_SetCurrentAnimation( CUSTOM_ANI_WILD_FLOWER_START );
		obj.sq_SetCurrentAttackInfo( ATTACKINFO_WILD_FLOWER_SLASH_ATTACK );
		
		obj.getVar("soundRandom").clear_vector();
		obj.getVar("soundRandom").push_vector( sq_getRandom(0,100).tointeger() );

		if (obj.getVar("soundRandom").get_vector(0) < 50)
			playSoundTime(obj,"SW_WILDFLOWER_02_A",100);
		else
			playSoundTime(obj,"SW_WILDFLOWER_02_B",100);

		local attackInfo = sq_GetCurrentAttackInfo(obj);
        local power = obj.sq_GetPowerWithPassive(SKILL_WILD_FLOWER, STATE_WILD_FLOWER , 1,-1,1.0);	 
        sq_SetCurrentAttackPower(attackInfo, power );

		local currentAttackInfo = sq_GetCurrentAttackInfo(obj);
		sq_SetCurrentAttackeHitStunTime(currentAttackInfo, 0);

		obj.getVar("flag").clear_vector();
		obj.getVar("flag").push_vector(0);
		obj.getVar("flag").push_vector(0);
		obj.getVar("flag").push_vector(0);
		obj.getVar("flag").push_vector(0);	

		obj.flashScreenOnlyMe(obj,[100,700,100],[0,0,0,76],2);
		obj.sq_setShakeOnlyMe(obj,3,100);

	}else if (state == 2)
	{
	

		if (obj.getVar("soundRandom").get_vector(0) < 50)
			playSoundTime(obj,"SW_WILDFLOWER_03_A",100);
		else
			playSoundTime(obj,"SW_WILDFLOWER_03_B",100);

		createWildFlowerEndAttackBack(obj);
		obj.sq_SetCurrentAnimation( CUSTOM_ANI_WILD_FLOWER_END );

		obj.sq_SetCurrentAttackInfo( ATTACKINFO_WILD_FLOWER_FINISH_ATTACK );
		
		local attackInfo = sq_GetCurrentAttackInfo(obj);
        local power = obj.sq_GetPowerWithPassive(SKILL_WILD_FLOWER, STATE_WILD_FLOWER , 2,-1,1.0);	 
        sq_SetCurrentAttackPower(attackInfo, power );

		obj.getVar("flag").clear_vector();
		obj.getVar("flag").push_vector(0);
		obj.getVar("flag").push_vector(0);
		obj.getVar("flag").push_vector(0);
		obj.getVar("flag").push_vector(0);	
		local pAni = obj.sq_GetCurrentAni();
		pAni.setSpeedRate(150.0 );
	}else if (state == 3)
	{
		obj.sq_SetCurrentAnimation( CUSTOM_ANI_WILD_FLOWER_END_S );
	}
}

function onProc_WildFlower(obj)
{

	local state = obj.getSkillSubState();
	
	if (state == 0)
	{
		local pAni = obj.sq_GetCurrentAni();
		local frmIndex = obj.sq_GetCurrentFrameIndex(pAni);

		local currentT = sq_GetCurrentTime(pAni);
		
		if (sq_IsEnd(pAni) == ture)
		{
			local pIntVec = sq_GetGlobalIntVector();
			sq_IntVectorClear(pIntVec);
			sq_IntVectorPush(pIntVec, 1);			
			obj.addSetStatePacket(STATE_WILD_FLOWER , pIntVec,  STATE_PRIORITY_USER, false, "");
		}else
		{
		
			if (frmIndex >= 2 && obj.getVar("flag").get_vector(0)  == 0)
			{
			
				obj.getVar("flag").set_vector(0,1);
				
			
			}
		
		}
		
		
		
	
	}else if (state == 1)
	{
		local pAni = obj.sq_GetCurrentAni();
		local frmIndex = obj.sq_GetCurrentFrameIndex(pAni);

		local currentT = sq_GetCurrentTime(pAni);
		
		if (sq_IsEnd(pAni) == ture)
		{
			local pIntVec = sq_GetGlobalIntVector();
			sq_IntVectorClear(pIntVec);
			sq_IntVectorPush(pIntVec, 2);			
			obj.addSetStatePacket(STATE_WILD_FLOWER , pIntVec,  STATE_PRIORITY_USER, false, "");
		}else
		{
		
			if (frmIndex >= 6 && obj.getVar("flag").get_vector(0)  == 0)
			{
			
				obj.getVar("flag").set_vector(0,1);
				local attackBonusRate = obj.sq_GetPowerWithPassive(SKILL_WILD_FLOWER, STATE_WILD_FLOWER , 0,-1,1.0);	
				obj.sq_StartWrite();
				obj.sq_WriteDword(attackBonusRate);	// attackBonusRate
				obj.sq_WriteDword(257);	// attackBonusRate
				obj.sq_WriteDword(5 );
				obj.sq_SendCreatePassiveObjectPacket(24357, 0, 200, 1, 89);
			
			}
		
		}
	
	}else if (state == 2)
	{
		local pAni = obj.sq_GetCurrentAni();
		local frmIndex = obj.sq_GetCurrentFrameIndex(pAni);

		local currentT = sq_GetCurrentTime(pAni);
		
		if (sq_IsEnd(pAni) == ture)
		{
			local pIntVec = sq_GetGlobalIntVector();
			sq_IntVectorClear(pIntVec);
			sq_IntVectorPush(pIntVec, 3);			
			obj.addSetStatePacket(STATE_WILD_FLOWER , pIntVec,  STATE_PRIORITY_USER, false, "");
		}else
		{
		
			if (frmIndex >= 3 && obj.getVar("flag").get_vector(0)  == 0)
			{
			
				obj.getVar("flag").set_vector(0,1);
				
				obj.flashScreenOnlyMe(obj,[0,100,50],[255,255,255,127],2);
				obj.sq_setShakeOnlyMe(obj,8,200);
				createWildFlowerEndDustFront(obj);
				createWildFlowerEndDustBack(obj);
			
			}
		
		}
	
	}else if (state == 3)
	{
		local pAni = obj.sq_GetCurrentAni();
		local frmIndex = obj.sq_GetCurrentFrameIndex(pAni);

		local currentT = sq_GetCurrentTime(pAni);
		
		if (sq_IsEnd(pAni) == ture)
		{
			local pIntVec = sq_GetGlobalIntVector();
			sq_IntVectorClear(pIntVec);
			sq_IntVectorPush(pIntVec, 2);			
			obj.addSetStatePacket(0, pIntVec,  STATE_PRIORITY_USER, false, "");
		}
	
	}
	
}


function onAttack_WildFlower(obj, damager, boundingBox, isStuck)
{

	local state = obj.getSkillSubState();
	createBladerHitEffect(obj,damager);
}



function createWildFlowerEndDustFront(obj)
{
	if(!obj || !sq_IsMyControlObject(obj) )
	return ;

	local ani = sq_CreateAnimation("","character/swordman/effect/animation/atwildflower/end_dust_front.ani");
	local pooledObj = sq_CreatePooledObject(ani,true);
	pooledObj.setCurrentPos(obj.getXPos() ,obj.getYPos() + 5,obj.getZPos() );
	pooledObj.setCurrentDirection(obj.getDirection());
	sq_AddObject(obj,pooledObj,2,false);	

}

function createWildFlowerEndDustBack(obj)
{
	if(!obj || !sq_IsMyControlObject(obj) )
	return ;

	local ani = sq_CreateAnimation("","character/swordman/effect/animation/atwildflower/end_dust_back.ani");
	local pooledObj = sq_CreatePooledObject(ani,true);
	pooledObj.setCurrentPos(obj.getXPos() ,obj.getYPos() - 5,obj.getZPos() );
	pooledObj.setCurrentDirection(obj.getDirection());
	sq_AddObject(obj,pooledObj,2,false);	

}


function createWildFlowerStartDustBack(obj)
{

	if(!obj || !sq_IsMyControlObject(obj) )
	return ;

	local ani = sq_CreateAnimation("","character/swordman/effect/animation/atwildflower/start_dustback_00.ani");
	local pooledObj = sq_CreatePooledObject(ani,true);
	pooledObj.setCurrentPos(obj.getXPos() ,obj.getYPos() - 5,obj.getZPos() );
	pooledObj.setCurrentDirection(obj.getDirection());
	sq_AddObject(obj,pooledObj,2,false);	

}



function createWildFlowerEndAttackBack(obj)
{

	if(!obj || !sq_IsMyControlObject(obj) )
	return ;

	local ani = sq_CreateAnimation("","character/swordman/effect/animation/atwildflower/endattackbback_00.ani");
	local pooledObj = sq_CreatePooledObject(ani,true);
	pooledObj.setCurrentPos(obj.getXPos() ,obj.getYPos() - 5,obj.getZPos() );
	pooledObj.setCurrentDirection(obj.getDirection());
	sq_AddObject(obj,pooledObj,2,false);	

}












